﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>融汇贷后台管理系统--登录</title>
    <link href="@Url.Content("~/Content/roohui/ligerUI/skins/Aqua/css/ligerui-dialog.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/roohui/ligerUI/skins/Gray/css/dialog.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Content/scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Content/roohui/ligerUI/js/core/base.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Content/roohui/js/plugins/ligerDrag.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Content/roohui/ligerUI/js/plugins/ligerDialog.js")" type="text/javascript"></script>
    <script type="text/javascript" src="/content/roohui/jquery-validation/jquery.validate.min.js"></script>
    <script type="text/javascript" src="/content/roohui/jquery-validation/jquery.metadata.js"></script>
    <script type="text/javascript" src="/content/scripts/plug.js"></script>
    <style type="text/css">
        *
        {
            padding: 0;
            margin: 0;
        }
        body
        {
            text-align: center;
            background: #4974A4;
        }
        #login
        {
            width: 740px;
            margin: 0 auto;
            font-size: 12px;
        }
        #loginlogo
        {
            width: 700px;
            height: 100px;
            overflow: hidden;
            background: url('content/images/logo.jpg') no-repeat;
            margin-top: 50px;
        }
        #loginpanel
        {
            width: 729px;
            position: relative;
            height: 300px;
        }
        .panel-h
        {
            width: 729px;
            height: 20px;
            background: url('content/images/panel-h.gif') no-repeat;
            position: absolute;
            top: 0px;
            left: 0px;
            z-index: 3;
        }
        .panel-f
        {
            width: 729px;
            height: 13px;
            background: url('content/images/panel-f.gif') no-repeat;
            position: absolute;
            bottom: 0px;
            left: 0px;
            z-index: 3;
        }
        .panel-c
        {
            z-index: 2;
            background: url('content/images/panel-c.gif') repeat-y;
            width: 729px;
            height: 300px;
        }
        .panel-c-l
        {
            position: absolute;
            left: 60px;
            top: 40px;
        }
        .panel-c-r
        {
            position: absolute;
            right: 20px;
            top: 50px;
            width: 222px;
            line-height: 200%;
            text-align: left;
        }
        .panel-c-l h3
        {
            color: #556A85;
            margin-bottom: 10px;
        }
        .panel-c-l td
        {
            padding: 7px;
        }
        .login-text
        {
            height: 30px;
            left: 24px;
            border: 1px solid #e9e9e9;
            background: #f9f9f9;
            font-size: 18px;
        }
        .login-text-focus
        {
            border: 1px solid #E6BF73;
        }
        .login-btn
        {
            width: 114px;
            height: 29px;
            color: #E9FFFF;
            line-height: 29px;
            background: url('content/images/login-btn.gif') no-repeat;
            border: none;
            overflow: hidden;
            cursor: pointer;
        }
        #txtUsername, #txtPassword
        {
            width: 191px;
        }
        #logincopyright
        {
            text-align: center;
            color: White;
            margin-top: 50px;
        }
        .login-button
        {
            width: 150px;
            height: 30px;
            margin: 0 auto;
            position: relative;
        }
        .login-button input
        {
            width: 150px;
            height: 30px;
            line-height: 30px;
            background: #15456f;
            border: 0;
            text-align: center;
            color: #fff;
            font-size: 16px;
            cursor: pointer;
        }
    </style>
    <script type="text/javascript">

        $(function () {
            $(".login-text").focus(function () {
                $(this).addClass("login-text-focus");
            }).blur(function () {
                $(this).removeClass("login-text-focus");
            });

            $(document).keydown(function (e) {
                if (e.keyCode == 13) {
                    dologin();
                }
            });

            $("#btnLogin").click(function () {
                dologin();
            });
            function dologin() {
                var username = $("#txtUsername").val();
                var password = $("#txtPassword").val();
                var validationCode = $("#checkcode").val();
                if (username == "") {
                    $.ligerDialog.warn('用户名不能为空！', '温馨提示');
                    $("#txtUsername").focus();
                    return;
                }
                if (password == "") {
                    $.ligerDialog.warn('密码不能为空！', '温馨提示');
                    $("#txtPassword").focus();
                    return;
                }
                if (validationCode == "") {
                    $.ligerDialog.warn('验证码不能为空！', '温馨提示');
                    $("#checkcode").focus();
                    return;
                }

                $.ajax({
                    type: 'post',
                    cache: false,
                    url: '/account/login',
                    data: 'userName=' + username + '&password=' + password + '&validateCode=' + validationCode + '&token=' + $("#token").val(),
                    success: function (result) {

                        result = eval("(" + result + ")");
                        if (!result) {
                            $.ligerDialog.warn('登录失败！', '温馨提示');
                            $("#txtUsername").focus();
                            return;
                        }
                        else {
                            if (result.RID == "1") {
                                location.href = decodeURIComponent("/home/index");
                            }
                            else if (result.RID == "99") {
                                //location.href = decodeURIComponent("/home/index");
                                //弹出手机输入验证码输入框
                                $("#phone").text(result.PHONE);
                                openCheck();
                            }
                            else if (result.RID == "-9") {
                                $.ligerDialog.warn('验证码错误！', '温馨提示');
                                $("#btnLogin").attr("disabled", false);
                                $("#checkcode").focus();
                            }
                            else if (result.RID == "-1") {
                                $.ligerDialog.warn('用户名不存在！', '温馨提示');
                                $("#btnLogin").attr("disabled", false);
                                $("#txtUsername").focus();
                            }
                            else if (result.RID == "-2") {
                                $.ligerDialog.warn('用户名已禁用，请联系管理员开通！', '温馨提示');
                                $("#btnLogin").attr("disabled", false);
                                $("#txtUsername").focus();
                            }
                            else if (result.RID == "-3") {
                                $.ligerDialog.warn('密码错误！', '温馨提示');
                                $("#btnLogin").attr("disabled", false);
                                $("#txtPassword").focus();
                            }
                            else {
                                $.ligerDialog.warn('未知错误，请联系管理员！', '温馨提示');
                                $("#btnLogin").attr("disabled", false);
                                $("#txtUsername").focus();
                            }
                        }
                    },
                    error: function () {
                        $.ligerDialog.warn('系统错误,请与系统管理员联系!', '温馨提示');
                    },
                    beforeSend: function () {
                        $.ligerDialog.waitting("正在登录中,请稍后...");
                        $("#btnLogin").attr("disabled", true);
                    },
                    complete: function () {
                        $.ligerDialog.closeWaitting();
                        $("#btnLogin").attr("disabled", false);
                    }
                });
            }
            $("#txtUsername").focus();
        }); 
        
    </script>
    <style type="text/css">
        .l-table-edit
        {
        }
        
        .l-table-edit-td
        {
            padding: 4px;
        }
    </style>
</head>
<body>
    <input type="hidden" name="token" id="token" />
    <div id="login">
        <div id="loginlogo">
        </div>
        <div id="loginpanel">
            <div class="panel-h">
            </div>
            <div class="panel-c">
                <div class="panel-c-l">
                    <table cellpadding="0" cellspacing="0">
                        <tbody>
                            <tr>
                                <td align="left" colspan="3">
                                    <h3>
                                        请使用融汇贷后台管理中心账号登录</h3>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    用户名：
                                </td>
                                <td align="left" colspan="2">
                                    <input type="text" name="loginusername" id="txtUsername" class="login-text" />
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    密&nbsp;&nbsp;码：
                                </td>
                                <td align="left" colspan="2">
                                    <input type="password" name="loginpassword" id="txtPassword" class="login-text" />
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    验证码：
                                </td>
                                <td align="left">
                                    <input type="text" name="checkcode" id="checkcode" class="login-text" style="width: 100px" />
                                </td>
                                <td>
                                    <div id="codeimg" style="margin-left: 10px; display: inline;">
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                </td>
                                <td align="left" colspan="2">
                                    <div class="login-button">
                                        <input name="btnLogin" type="button" value="登录" id="btnLogin">
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="panel-c-r">
                    待设计，哈哈
                </div>
            </div>
            <div class="panel-f">
            </div>
        </div>
        <div>
            <form action="/" method="post" id="frmValide" name="frmValide" style="background-color: white;
            display: none">
            <table cellpadding="0" cellspacing="0" class="l-table-edit">
                <tr>
                    <td align="right" class="l-table-edit-td">
                        手机号：
                    </td>
                    <td align="left" class="l-table-edit-td" colspan="2">
                        <span id="phone" style="font-size: 20px; font-weight: bold"></span>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="l-table-edit-td">
                        验证码：
                    </td>
                    <td align="left" class="l-table-edit-td">
                        <input name="txtCheckCode" type="text" id="txtCheckCode" style="width: 80px" class="login-text"
                            validate="{required:true}" />
                    </td>
                    <td align="left">&nbsp;<span id="sendcheck"><a href="#" onclick="sendshortmessage()">发送验证码</a></span><span
                                id="surplustime" style="display:none"></span>
                    </td>
                </tr>
            </table>
            </form>
        </div>
    </div>
</body>
<script src="@Url.Content("~/Content/roohui/jquery-validation/jquery.validate.min.js")"></script>
<script src="@Url.Content("~/Content/roohui/jquery-validation/jquery.metadata.js")"></script>
<script src="@Url.Content("~/Content/roohui/jquery-validation/messages_cn.js")"></script>
<script type="text/javascript">

    var validation = new plug.BindValidCode();
    $(function () {
        validation.BindValidator();

    });
    var checkdialog;
    function openCheck() {
        checkdialog = $.ligerDialog.open({
            title: "短信验证",
            id: 'vDialog',
            name: 'vDialog',
            slide: false,
            isHidden: false,
            modal: true,
            target: $("#frmValide"),
            width: 260, height: 150, isResize: false, allowClose: false,
            buttons: [
               { text: '确定', onclick: check }
//                {
//                    text: '取消', onclick: function (item, dialog) {
//                        dialog.hide();
//                        //role_reset();
//                    }
//                }
            ]
        });

    }
    function check() {
        var userName = $("#txtUsername").val();
        var checkeCode = $("#txtCheckCode").val();
        $.ajax({
            url: "Account/CheckShortMessageCode",
            data: 'userName=' + userName + '&checkCode=' + checkeCode,
            type: 'Post',
            success: function (result) { 
                if (result == "1") {
                    location.href = decodeURIComponent("/home/index");
                    $("#txtCheckCode").val("");
                }
                else {
                    //checkdialog.hide();
                    var manager = $.ligerDialog.waitting('验证码输入错误'); setTimeout(function () { manager.close(); }, 1000);
                    $("#txtCheckCode").val("");
//                    $("#sendcheck").css("display", "block");
//                    $("#surplustime").css("display", "none");   
                }
            }
        });
    }
    function sendshortmessage() {
        var userName = $("#txtUsername").val();
        $("#txtCheckCode").val("");
        $.ajax({
            url: "Account/ResendShortMessage",
            data: 'userName=' + userName,
            type: 'Post',
            success: function (result) {
                if (result == "1") {
                    var manager = $.ligerDialog.waitting('验证码已发送...'); setTimeout(function () { manager.close(); }, 1000);
                   
                    timeclick();
                }
            }
        });
    }
    function Refalsh(sender) {
        validation.Refalsh(sender);
    }
    
    function timeclick() {
        $("#sendcheck").css("display", "none");
        $("#surplustime").css("display", "block");
        $("#surplustime").html("100秒后失效");
        jump(100);
    }
   
    function jump(count) {
        window.setTimeout(function () {
            count--;
            if (count > 0) {
                $("#surplustime").html(count + "秒后失效");
                jump(count);
            } else {
                $("#sendcheck").css("display", "block");
                $("#surplustime").css("display", "none");   
            }
        }, 1000);
    }
</script>
</html>
